package com.learn.springcloud.hystrixturbineconsumerwhoareyou.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @Time : 2018/8/7 17:28
 * @Version : 1.0
 */
@RestController
public class HystrixTurbineConsumerSayHello {

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/hystrix/turbine/say/hello/{name}")
    @HystrixCommand(fallbackMethod = "sayHelloFallback")
    public String sayHello(@PathVariable String name){
        System.out.println(name);
        String url = "http://hystrix-turbine-provider/hystrix/turbine/provider/say/hello/{1}";
        return restTemplate.getForObject(url, String.class, name);
    }

    private String sayHelloFallback(String name){
        return "error, " + name;
    }

}
